import {https} from "@/utils/request";
import {LoginFormProp} from "@/pages/login";
import {UserState} from "@/redux/user/reducer";
import {RegisterFormProp} from "@/pages/login/modules";
import {PageData} from "@/utils/http";
import {UserDetailProp, UserEditFormProp, UserListProp, UserQueryProp} from "@/pages/authority/modules";

export const userLogin = (data: LoginFormProp): Promise<UserState> => {
	return https.request({
		url: '/user/login',
		method: 'post',
		data: data
	}, {})
}

// sendCaptcha 发送验证码
export const sendCaptcha = (data: string): Promise<string> => {
	return https.request({
		url: '/user/captcha',
		method: 'get',
		params: {email: data}
	})
}

// userRegister 用户注册
export const userRegister = (data: RegisterFormProp): Promise<boolean> => {
	return https.request({
		url: '/user/register',
		method: 'post',
		data: data
	})
}

// userPage 用户分页
export const userPage = (data: UserQueryProp): Promise<PageData<UserListProp>> => {
	return https.request({
		url: '/authority/user/page',
		method: 'post',
		data: data
	})
}

// updateUser 用户更新
export const updateUser = (data: UserEditFormProp): Promise<string> => {
	return https.request({
		url: '/authority/user/update',
		method: 'post',
		data: data
	})
}

// userResetPassword 用户重置密码
export const userResetPassword = (id: number): Promise<string> => {
	return https.request({
		url: '/authority/user/resetPasswd',
		method: 'get',
		params: {id: id}
	})
}

// getUserDetail 获取用户详情
export const getUserDetail = (id: number): Promise<UserDetailProp> => {
	return https.request({
		url: '/authority/user/detail',
		method: 'get',
		params: {id: id}
	})
}

// userDelete 用户删除
export const userDelete = (ids: string): Promise<string> => {
	return https.request({
		url: '/authority/user/delete',
		method: 'get',
		params: {ids: ids}
	})
}